{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">

                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px">
                            <input type="text" id="keyword" class="layui-input search" name="keyword" value="" placeholder="商品-名字/分类/品牌/风格"/>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <select name="good_s_t_id" class="layui-input">
                                <option value="">不限分类</option>
                                {volist name='type1' id='t'}
                                <option value="{$t.t_id}">{$t.t_name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <select name="good_s_pp_id" class="layui-input">
                                <option value="">不限品牌</option>
                                {volist name='pp1' id='t'}
                                <option value="{$t.pp_id}">{$t.pp_name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <select name="good_status" class="layui-input">
                                <option value="">不限状态</option>
                                <option value="1">正常</option>
                                <option value="2">冻结</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <select name="good_t_id" class="layui-input">
                                <option value="">不限商品分类</option>
                                {volist name='types' id='t'}
                                <option value="{$t.st_id}">{$t.st_name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <select name="good_pp_id" class="layui-input">
                                <option value="">不限商品品牌</option>
                                {volist name='pps' id='t'}
                                <option value="{$t.spp_id}">{$t.spp_name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <select name="good_style_id" class="layui-input">
                                <option value="">不限商品风格</option>
                                {volist name='styles' id='t'}
                                <option value="{$t.sstyle_id}">{$t.sstyle_name}</option>
                                {/volist}
                            </select>
                        </div>

                        <div class="layui-input-inline" style="margin-top: 5px">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.layer_show('新建产品', '{:url('goodAdd')}')">
                            <i class="fa fa-plus"></i> 添加产品
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>
                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.good_thumb}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"/>
                    </script>
                    <script type="text/html" id="staBar">
                        <input type="checkbox" value="{{d.good_id}}"  lay-skin="switch"  lay-text="启用|禁用" lay-filter="OnOff" {{ d.good_status == 1 ? 'checked' : '' }} >
                    </script>
                    <script type="text/html" id="topBar">
                        <input type="checkbox" value="{{d.good_id}}"  lay-skin="switch"  lay-text="置顶|正常" lay-filter="OnOff2" {{ d.good_top == 2 ? 'checked' : '' }} >
                    </script>
                    <script type="text/html" id="topBar2">
                        <input type="checkbox" value="{{d.good_id}}"  lay-skin="switch"  lay-text="是|否" lay-filter="OnOff3" {{ d.good_index == 2 ? 'checked' : '' }} >
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.layer_show('编辑/详情', '{:url('goodEdit')}?good_id={{d.good_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑"><i class="fa fa-pencil">编辑</i></a>
                        <a href="javascript:;" onclick="wk.layer_show('文件设置', '{:url('newBanner')}?good_id={{d.good_id}}')" class="btn btn-primary btn-xs m-r-xs" title="文件设置"><i class="fa fa-pencil">文件设置</i></a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.good_id}}','{:url('goodDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o">删除</i></a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Goods/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left'},
                {type:'numbers', width: 60, title: '序号'}
                , {field: 'good_name', width: 110, title: '产品名字', align: 'center'}
                , {field: 'good_thumb', width: 110, title: '缩略图', align: 'center', templet: '#imgTpl'}
                , {field: 't_name', width: 110, title: '分类', align: 'center'}
                , {field: 'pp_name', width: 110, title: '品牌', align: 'center'}
                , {field: 's_names', width: 110, title: '所属门店', align: 'center'}
                , {field: 'st_name', width: 110, title: '商品分类', align: 'center'}
                , {field: 'spp_name', width: 110, title: '商品品牌', align: 'center'}
                , {field: 'sstyle_name', width: 110, title: '商品风格', align: 'center'}
                , {field: 'good_money_name', width: 110, title: '价格文案', align: 'center'}
                , {field: 'good_money_min', width: 110, title: '低价(可编辑)', align: 'center', edit: 'test'}
                , {field: 'good_money_max', width: 110, title: '高价(可编辑)', align: 'center', edit: 'test'}
                , {field: 'good_sort', width: 110, title: '排序(可编辑)', align: 'center', edit: 'test'}
                , {field: 'good_time', width: 160, title: '新建时间', align: 'center'}
                , {field: 'good_status', fixed: 'right',width: '100', title: '状态', align: 'center', templet: '#staBar'}
                , {field: 'good_top',fixed: 'right', width: 100, title: '置顶', align: 'center', templet: '#topBar'}
                , {field: 'good_index',fixed: 'right', width: 100, title: '主页面推荐', align: 'center', templet: '#topBar2'}
                , {fixed: 'right', width: 230, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.table-img').viewer({
                    url: 'data-original',
                });
            }
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("changeGoodStatus")}',obj);
        });
        form.on('switch(OnOff2)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 2: num = 1;
            //用户状态
            wk.status(this.value,num, '{:url("changeGoodTop")}',obj);
        });
        form.on('switch(OnOff3)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 2: num = 1;
            //用户状态
            wk.status(this.value,num, '{:url("changeIndexTop")}',obj);
        });
        //监听单元格编辑---排序
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            wk.change(data.good_id,"{:url('updateGoodSort')}",field,value);
        });
        //批量操作
        var $ = layui.$, active = {
            getCheckData: function(){
                //批量删除
                wk.batchDel(getIds(),"{:url('batchDel')}");
            },
            getCheckDataSet: function(){
                //批量启用
                wk.usingAll(getIds(),'',"{:url('batchSetTwoPics')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['good_id'])
            });
            return ids;
        }

    });
</script>
</body>
</html>